//
//  AdviseView.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/9/12.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class AdviseView: UIView,UITextViewDelegate {
    var adviseTextView:UITextView!
    var hintLabel:UILabel!
    var sendButton:UIButton!
    override init(frame: CGRect) {
        adviseTextView = UITextView()
        hintLabel = UILabel()
        sendButton = UIButton()
        super.init(frame: frame)
        self.backgroundColor = Theme.BGColor
        self.addTextView()
        self.addHintMessage()
        self.createSendButton()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //添加输入框
    func addTextView(){
        adviseTextView.frame = CGRect(x: 11*SCALEW, y: 11*SCALEH, width: 353*SCALEW, height: 181*SCALEH)
        adviseTextView.layer.borderWidth = 1
        adviseTextView.layer.borderColor = BaseFunc.createCustomColor(221, b: 221, g: 221, a: 1).CGColor
        adviseTextView.keyboardType = .Default
        adviseTextView.font = BaseFunc.getCustomFont(13)
        adviseTextView.delegate = self
        self.addSubview(adviseTextView)
    }
    
    //添加提示文字
    func addHintMessage(){
        hintLabel.frame = CGRect(x: 0, y: 94*SCALEH, width: WidthAPP, height: 16*SCALEH)
        hintLabel.textColor = Theme.GrayColor
        hintLabel.text = "请留下您的意见和批评，一起来帮助三人行成长吧～"
        hintLabel.textAlignment = .Center
        hintLabel.font = BaseFunc.getCustomFont(12)
        self.addSubview(hintLabel)
    }
    
    //创建发送按钮
    func createSendButton(){
        sendButton.frame = CGRect(x: 33*SCALEW,y: 212*SCALEH,width: 309*SCALEW,height: 50*SCALEH)
        sendButton.setTitle("发送", forState: UIControlState())
        sendButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState())
        sendButton.backgroundColor = UIColor.blackColor()
        sendButton.titleLabel?.font = BaseFunc.getCustomFont(18)
        sendButton.layer.cornerRadius = 5
        self.addSubview(sendButton)
    }
    
    
    func textViewShouldBeginEditing(textView: UITextView) -> Bool {
        self.hintLabel.alpha = 0
        return true
    }
    
    func textViewShouldEndEditing(textView: UITextView) -> Bool {
        if textView.text == ""{
            self.hintLabel.alpha = 1
        }
        return true
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        adviseTextView.resignFirstResponder()
    }
}
